package pl.edu.pw.ee.buildcity.services;

import pl.edu.pw.ee.buildcity.dao.GenericDao;

import javax.annotation.Resource;
import java.io.Serializable;
import java.util.List;

/**
 * @author mgrzechocinski
 * @since 2009-11-22
 */
public class GenericEntityService<T, PK extends Serializable> {

	@Resource(name = "jpaGenericDao")
	private GenericDao<T, PK> dao;

	public List<T> getAll(Class<T> entity) {
		return dao.executeQuery("from " + entity.getSimpleName());
	}

	public void persist(T entityToPersist) {
		dao.persist(entityToPersist);
	}

	public void delete(T entityToRemove) {
		dao.remove(entityToRemove);
	}

	public T update(T buildDefinition) {
		return dao.merge(buildDefinition);
	}
}
